<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>子组件向父组件绑定数据</title>
</head>

<body>
    <pre>
        子组件向父组件绑定数据通过事件绑定

    </pre>
    <div class="app">
        <div>{{num}}</div>
        <hello-vue :arr="arr" @enlarge='cal($event)'></hello-vue>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        Vue.component('hello-vue', {
            props: ['arr'],
            template: `
            <div>
                <p v-for="(item,index) in arr" :key='index'>{{item}}</p>
                <button @click='handel'>点击</button>
                <button @click="$emit('enlarge',20)">点击</button>
            </div>
            `,
            methods: {
                handel: function () {
                    this.arr.push('lemon')
                }
            }
        })
        var xm = new Vue({
            el: '.app',
            data: {
                num: 0,
                arr: ['apple', 'pear']
            },
            methods: {
                cal: function (val) {
                    this.num = val
                }
            }
        })



    </script>

</body>

</html>